﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Consumer Manage - Open API Control Panel
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <fieldset>
        <legend>Consumer Manage &gt; Consumer List</legend>
        <table border="0" cellpadding="0" cellspacing="0" width="100%">
            <tr>
                <td width="120">
                    <strong>Consumer Name</strong>
                </td>
                <td width="120">
                    <strong>Consumer Key</strong>
                </td>
                <td width="120">
                    <strong>Consumer Secret</strong>
                </td>
                <td align="center">
                    <strong>Manage</strong>
                </td>
            </tr>
            <%
                foreach (ConsumerInfo consumer in ViewData["Consumers"] as List<ConsumerInfo>)
                {
            %>
            <tr>
                <td>
                    <%= consumer.CONSUMER_NAME%>
                </td>
                <td>
                    <%= consumer.OAUTH_CONSUMER_KEY%>
                </td>
                <td>
                    <%= consumer.OAUTH_CONSUMER_SECRET%>
                </td>
                <td width="120" align="center">
                    [<%= Html.ActionLink("Modify", "ConsumerModify", "Consumer", new { id = consumer.OAUTH_CONSUMER_KEY }, null)%>]
                    [<a href="javascript:void(0);" onclick="javascript:Delete('<%=consumer.OAUTH_CONSUMER_KEY %>','<%=consumer.OAUTH_CONSUMER_SECRET %>');">Delete</a>]
                </td>
            </tr>
            <%
                }
            %>
        </table>
        <input type="button" id="btnRegister" name="btnRegister" value="Register Consumer" />
    </fieldset>

    <script type="text/javascript" language="javascript">

        $().ready(function() {
            $("#btnRegister").click(function() {
                location.href = "/Consumer/ConsumerRegister";
            })
        })

        function Delete(oauth_consumer_key, oauth_consumer_secret) {

            if (confirm('Are you sure delete?')) {

                $.post("/Consumer/DeleteConsumer?" + new Date(), {
                    Action: "post",
                    oauth_consumer_key: oauth_consumer_key,
                    oauth_consumer_secret: oauth_consumer_secret
                }, function(result) {
                    if (result.FLAG) {
                        alert(result.DESC);
                        location.href = "/Consumer/ConsumerList";
                    }
                    else {
                        alert(result.DESC);
                    }
                })
            }
        }
    </script>

</asp:Content>
